<?php
namespace app\common\controller;

/**
 * pdf类
 * Created by PhpStorm.
 * User: tyll
 * Date: 2020/03/11
 * Time: 13:24
 */
class Pdf {

    /**
     * 生成工位/办公室pdf
     * @param $wx_list
     */
    public function gen_ws_pdf($wx_list){
        $pdf = new \TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

        $pdf->SetCreator(PDF_CREATOR);
        $pdf->SetAuthor('tyll');
        $pdf->SetTitle('工位/办公室小程序码');
        $pdf->SetSubject('TCPDF Tutorial');
        $pdf->SetKeywords('TCPDF, PDF, example, test, guide');

        $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
        $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

        $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

        $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);

        $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
        $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

        $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

        $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

        if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
            require_once(dirname(__FILE__).'/lang/eng.php');
            $pdf->setLanguageArray($l);
        }

        $pdf->SetFont('stsongstdlight', 'B', 20);

        $pdf->AddPage();

        $pdf->setJPEGQuality(75);

        $imgdata = base64_decode('iVBORw0KGgoAAAANSUhEUgAAABwAAAASCAMAAAB/2U7WAAAABlBMVEUAAAD///+l2Z/dAAAASUlEQVR4XqWQUQoAIAxC2/0vXZDrEX4IJTRkb7lobNUStXsB0jIXIAMSsQnWlsV+wULF4Avk9fLq2r8a5HSE35Q3eO2XP1A1wQkZSgETvDtKdQAAAABJRU5ErkJggg==');

        $pdf->Image('@' . $imgdata);

        foreach ($wx_list as $k => $v){
            if(!empty($v['wechat_mini_code_pic'])){
                $pdf->Image($v['wechat_mini_code_pic'], '', '', 90, 90, '', '', 'N', false, 300, 'C', false, false, 0, false, false, false);

                $pdf->Write(0, $v['branch_zw'] . '-' . $v['floor_zw'] . '-' . $v['number'], '', 0, 'C', true, 0, false, false, 0);

                $pdf->ln(15);
            }
        }

        $pdf->Output('ws.pdf', 'D');
    }
}